package com.a0soft.gphone.aTruffleHog.util;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */

import java.util.List;

import android.content.SharedPreferences;
import android.hardware.Camera;
import android.hardware.Sensor;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */
import android.hardware.Camera.CameraInfo;

public class SDK9 {
	private static SDK9	m_inst;
	
	private SDK9() {}
	
	public static SDK9
	GetInstance()
	{
		if (m_inst == null)
			m_inst = new SDK9();
		return m_inst;
	}
	
	public boolean 
	Environment_isExternalStorageRemovable()
	{
		return android.os.Environment.isExternalStorageRemovable();
	}
    
	public void 
    SharedPreferencesEditor_Apply(SharedPreferences.Editor ed)
    {
        ed.apply();
    }
	
    public int
    Camera_GetNumberOfCameras()
    {
        try {
            return Camera.getNumberOfCameras();
        } catch (Exception e) {
            //java.lang.NoSuchMethodError: android.hardware.Camera.getNumberOfCameras
            //strange problem, this api should be built-in in SDK9
            return 1;
        }
    }
    
    public int
    Camera_GetFacingType(int nID)
    {
        CameraInfo info = new CameraInfo();
        try {
            Camera.getCameraInfo(nID, info);
            return info.facing;
        } catch (Exception e) {
            return CameraInfo.CAMERA_FACING_BACK;
        }
    }
    
    public int
    Camera_GetOrientation(int nID)
    {
        CameraInfo info = new CameraInfo();
        try {
            Camera.getCameraInfo(nID, info);
            return info.orientation;
        } catch (Exception e) {
            return 0;
        }
    }
    
    public Camera
    Camera_Open(int nID)
    {
        try {
            return Camera.open(nID);
        } catch (Exception e) {
            return null;
        }
    }
    
    public List<int[]>
    CameraParameters_GetSupportedPreviewFpsRange(Camera.Parameters params)
    {
        return params.getSupportedPreviewFpsRange();
    }
    
    public int
    Sensor_GetMinDelay(Sensor oSensor)
    {
        return ((oSensor != null)? oSensor.getMinDelay(): -1);
    }
}